﻿/*******************************************************
*类名称：WechatImageTextGroupManager
*版本号：V1.0.0.0
*作者：成俊杰
*CLR版本：4.0.30319.36264
*创建时间：2017-09-11 16:35:34
*说明：T_WechatImageTextGroup管理类
*更新备注：
**********************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wechat.Dao;
using Wechat.Domain;
using Wechat.Dto.Request;
using Wechat.Dto.Search;
using Wechat.Util.ReturnMessage;
using Wechat.Util.StateCode;

namespace Wechat.Manager.Implement
{
    /// <summary>
    /// T_WechatImageTextGroup
    /// </summary>
    public class WechatImageTextGroupManager : GenericManagerBase<WechatImageTextGroup>, IWechatImageTextGroupManager
    {
        public IWechatImageTextRepository WechatImageTextRepository { get; set; }

        /// <summary>
        /// 添加或修改图文组消息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ResultMessage InsertOrUpdateImageTextGroup(WechatImageTextRequest request)
        {
            ResultMessage returnMsg = new ResultMessage()
            {
                Status = false,
                Message = request.Id > 0 ? "修改图文消息失败" : "添加图文消息失败"
            };
            var result = 0;
            if (request.GroupId == 0)
            {
                WechatImageTextGroup model = new WechatImageTextGroup()
                {
                    Title = request.Title,
                    IsGroup = true
                };
                request.GroupId = Insert(model);
            }
            if (request.GroupId > 0)
            {
                result = WechatImageTextRepository.InsertOrUpdateImageText(request);
                if (result > 0)
                {
                    returnMsg.Data = request.GroupId;
                    returnMsg.Code = (int)EnumApiStateCode.Success;
                    returnMsg.Message = request.Id > 0 ? "修改图文消息组成功" : "添加图文消息组成功"; ;
                    returnMsg.Status = true;
                }
                else
                {
                    returnMsg.Message = request.Id > 0 ? "修改图文消息失败" : "添加图文消息失败"; ;
                }
            }
            else
            {
                returnMsg.Message = request.Id > 0 ? "修改图文消息组失败" : "添加图文消息组失败"; ;
            }

            return returnMsg;
        }

    }
}